home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / asm_0_m.arj / DOSMON.ASM < prev    next >
Assembly Source File  |  1989-05-26  |  5KB  |  233 lines

  1. ;
  2. ;----------------------------------------
  3. ; DOSMON - DOS Activity Monitor
  4. ;----------------------------------------
  5. ;
  6. ; This program will terminate and stay resident.  It intercepts the
  7. ; DOS service interrupt and displays status information on the
  8. ; screen during DOS service execution periods.
  9. ;
  10. ; S.H.Smith, 15-may-86
  11. ; converted to real assembly, sped up, and made smaller by 
  12. ; jack velte 1301 441-2008  velte@mimsy.umd.edu
  13. ;
  14.  
  15. RESLEN    equ  init - dosmon + 256
  16.  
  17. code    segment    byte public 'text'
  18.     assume cs:code, ds:code
  19.     org    100h
  20.  
  21. ;----------------------------------------
  22. ; startup entry point
  23. ;----------------------------------------
  24. dosmon    proc    near
  25.     jmp short init    ;install
  26. dosmon    endp
  27.  
  28. ; segment address for display memory
  29. ; filled in by startup code
  30. display_seg    dw    ?
  31. twiddle_idx    dw    ?    ; twiddle display index
  32. twiddle_char    db '─\│/'    ; twiddle display characters
  33.  
  34. ;----------------------------------------
  35. ; new DOS service interrupt
  36. ;----------------------------------------
  37. ;
  38. new21 proc far
  39.     push ds
  40.     push es
  41.     push bx        ; save entry registers
  42.     push ax
  43.  
  44.     mov ax, cs:display_seg        ; get display segment into es
  45.     mov es, ax
  46. ;
  47. ;----------------------------------------
  48. ; prepare display with blanks
  49. ;
  50.     mov ax, 0f20h        ;space with attribute of 15
  51.     mov es:[94h], ax
  52.     mov es:[96h], ax    ;set attribute of the function code locations
  53.     mov es:[98h], ax
  54. ;
  55. ;----------------------------------------
  56. ; display the rotating twiddle character
  57. ;
  58.     mov bx, cs:twiddle_idx    ;get twiddle index
  59.     inc bx
  60.     mov al, bl        ;advance to next twiddle position
  61.     and al, 3        ;bx=bx mod 4 to rotate through twiddles
  62.     mov bl, al
  63.     mov cs:twiddle_idx, bx    ;save next twiddle index
  64.  
  65.     mov ah, cs:[twiddle_char + bx]     ;get the next twiddle character
  66.     mov es:[94h], ah        ;put twiddle status on screen
  67. ;
  68. ;----------------------------------------
  69. ; display the DOS service number in hex
  70. ;
  71.     pop bx        
  72.     mov ax, bx        ;get the dos function code into ah
  73.  
  74.     and ah, 0fh
  75.     add ah, 30h        ;convert low digit to hex
  76.  
  77.     cmp ah, 3ah        ;handle A..F
  78.     jb foo
  79.     add ah, 7
  80. foo:
  81.     mov es:[98h], ah    ;and set LSB on screen
  82.  
  83.     mov ax, bx        ;get fresh copy of function code into ah
  84.  
  85.     shr ah, 1        ;move down bits for high digit
  86.     shr ah, 1
  87.     shr ah, 1
  88.     shr ah, 1        ;make high byte hex and put on screen
  89.     and ah, 0fh
  90.     add ah, 30h
  91.  
  92.     cmp ah, 3ah        ;handle A..F
  93.     jb bar
  94.     add ah, 7
  95. bar:
  96.     mov es:[96h], ah        ;set MSB on screen
  97.  
  98. ;----------------------------------------
  99. ; perform the DOS service function
  100. ;
  101.     mov ax, bx    ; we've been saving it here.
  102.     pop bx
  103.     pop es        ;restore initial entry registers
  104.     pop ds
  105. ;
  106.     db 0eah        ;   pass to original int21 code
  107. int21ofs    dw ?    ; *** self-modifying code:
  108. int21seg    dw ?    ; *** JMP FAR PTR xxxx:yyyy
  109.  
  110. new21    endp
  111.  
  112.  
  113. ;----------------------------------------
  114. ; startup code
  115. ;----------------------------------------
  116. ; determine where the video ram is.  this is done by putting a special
  117. ; character on the screen and then looking for it in the various video
  118. ; ram locations.
  119. ;
  120. init proc near
  121.     push cs
  122.     pop ds        ; get cs in ds
  123.  
  124.     mov ah, 3    ;get cursor position
  125.     int 10h        ;video bios service
  126.  
  127.     push ax
  128.     push bx
  129.     push dx         ;save it for later
  130.  
  131.     mov dx, 0
  132.     mov ah, 2         ;home the cursor
  133.     int 10h
  134.  
  135.     mov ah, 0Ah
  136.     mov al, 88h         ;display a funny char at cursor
  137.     mov cx, 1
  138.     int 10h
  139. ;
  140. ; move cursor back to original position
  141. ;
  142.     pop dx
  143.     pop bx
  144.     pop ax
  145.     mov ah, 2
  146.     int 10h
  147. ;
  148. ; look for MONO video ram
  149. ;
  150.     mov dl, 88h
  151.     mov ax, 0b000h
  152.     mov es,ax
  153.     cmp dl, es:[0]
  154.     jz foundvideo
  155. ;
  156. ; look for COLOR video ram
  157. ;
  158.     mov ax, 0b800h
  159.     mov es, ax
  160.     cmp dl, es:[0]
  161.     jz foundvideo
  162. ;
  163. ; couldn't find video ram; display a message and abort
  164. ;
  165.     lea dx, errormsg
  166.     mov ah,9
  167.     int 21h         ;display error message
  168.  
  169.     mov ah, 4ch    ; terminate with error code
  170.     mov al, 1
  171.     int 21h
  172.  
  173. errormsg:
  174.     db "ERROR: Can't find display memory$"
  175.  
  176.  
  177. foundvideo:
  178.     mov cs:display_seg, ax         ;set the display segment
  179. ;
  180. ;----------------------------------------
  181. ; display the program signon message now that we are sure
  182. ; that we can be installed
  183. ;
  184.     lea dx, signon_msg
  185.     mov ah, 9
  186.     int 21h         ;display signon message
  187.  
  188.     mov    es, ds:[002Ch]
  189.     mov    ah, 49h         ; free up our copy of the environment
  190.     int    21h
  191.  
  192. ;----------------------------------------
  193. ; now install new interrupt handler
  194. ;
  195.     mov ax,0
  196.     mov es,ax
  197. ;
  198. ; save old DOS service vector
  199. ;
  200.     mov    ax, 3521h       
  201.     int    21h
  202.     mov    int21ofs, bx        ; save old int21
  203.     mov    int21seg, es        ;
  204.     mov    ax, 2521h        ; install new vector
  205.     lea    dx, new21        ; ptr to our routine
  206.     int    21h
  207.  
  208. ;
  209. ; set last resident code offset
  210. ; and terminate-and-stay-resident
  211. ;
  212.     mov    dx, RESLEN      ; size of our interrupt handler
  213.         test    dl,0Fh             ; see if it's on a paragraph boundary
  214.     sahf
  215.     mov    cl, 4
  216.     shr    dx, cl        ; convert bytes to paragraphs
  217.     lahf            ; paragraph aligned?
  218.     jz     gotsr        ;   yes, we're done
  219.     inc    dx        ; round to next paragraph
  220. gotsr:    mov    ax, 3100h       ; terminate and stay resident
  221.     int    21h
  222. init    endp
  223.  
  224.  
  225. ; a signature in bytes
  226. signon_msg:
  227.     db 0ah, 0dh, "DOSMON - DOS Activity Monitor", 0ah, 0dh
  228.     db "S.H.Smith, 15-May-86", 0ah, 0dh
  229.     db "jack velte, may 89", 0ah, 0dh, "$"
  230.  
  231. code      ends
  232.           end        dosmon
  233.